//
//  GuidePageView.m
//  QiYReader
//
//  Created by 奇阅科技 on 15/1/15.
//  Copyright (c) 2015年 奇阅科技. All rights reserved.
//

#import "GuidePageView.h"
#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
@implementation GuidePageView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(id)initWithGuideImage:(UIImage *)image{
    self = [super init];
    if (self) {
        self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:self.bounds];
        imageView.image = image;
        [self addSubview:imageView];
        imageView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(closeView)];
        [imageView addGestureRecognizer:tap];
        UISwipeGestureRecognizer *leftSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(closeView)];
        UISwipeGestureRecognizer *rightSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(closeView)];
        
        leftSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
        rightSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
        
        [imageView addGestureRecognizer:leftSwipeGestureRecognizer];
        [imageView addGestureRecognizer:rightSwipeGestureRecognizer];
    }
    return self;
}
-(void)showView{
    UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
    [keyWindow addSubview:self];
}
- (void)closeView{
    if ([self.delegate respondsToSelector:@selector(guidePageViewcancel)]) {
        [self.delegate guidePageViewcancel];
    }
    [self removeFromSuperview];
}
@end
